/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jmooc.dao.jpa;

import com.jmooc.dao.QuestionDao;
import com.jmooc.entity.Course;
import com.jmooc.entity.Question;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

/**
 *
 * @author Group
 */
@Stateless
public class JpaQuestionDao implements QuestionDao {
    
    @PersistenceContext
    private EntityManager em;

    @Override
    public List<Question> getAllByCourse(Course course) {
        return em.createQuery("SELECT q FROM Question q WHERE q.course = :c").setParameter("c", course).getResultList();
    }

    @Override
    public void create(Question question) {
        em.persist(question);
    }

    @Override
    public void update(Question question) {
        em.merge(question);
    }

    
 

}
